﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AAA.Algorithm.Data
{
    public class FutureGroup : IFutureGroup
    {
        private Dictionary<string, List<string>> _dicGroup;
        private string _strRootName;

        public FutureGroup()
        {
            _dicGroup = new Dictionary<string, List<string>>();
        }
        
        #region IFutureGroup Members

        public string RootName
        {
            get { return _strRootName; }
            set { _strRootName = value; }
        }

        public void AddGroup(string strGroupName, string strFuture)
        {
            List<string> lstFuture;
            try
            {
                if (_dicGroup.ContainsKey(strGroupName) == false)
                {
                    lstFuture = new List<string>();
                    _dicGroup.Add(strGroupName, lstFuture);
                }

                lstFuture = _dicGroup[strGroupName];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "," + ex.StackTrace);
            }
        }

        public List<string> GetFuture(string strGroupName)
        {
            return _dicGroup.ContainsKey(strGroupName)
                    ? _dicGroup[strGroupName]
                    : null;
        }

        public bool IsParentNode(string strGroupName)
        {
            try
            {
                return _dicGroup.ContainsKey(strGroupName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "," + ex.StackTrace);
            }
            return false;
        }

        public List<string> GroupNames()
        {
            List<string> lstGroupName = new List<string>();

            foreach (string strName in _dicGroup.Keys)
                lstGroupName.Add(strName);
            return lstGroupName;
        }

        #endregion
    }
}
